home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Demo's / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Data Manipulation / XYZtoMatrix < prev   
Text File  |  1996-01-29  |  3KB  |  89 lines

  1. | XYZtoMatrix
  2. | This procedure file contains two macros to convert X, Y, and Z values
  3. | into a 2-D matrix of Z values:
  4. | XYZtoMatrix, which converts the entire XY domain into a matrix
  5. | and XYZtoMatrixRange, which converts a given XY domain into a matrix.
  6.  
  7. // Converts three waves containing X, Y, and Z values into
  8. // a matrix of Z values that spans the min and max X and Y.
  9. Macro XYZtoMatrix(wx,mat,wy,rows,wz,cols,mktbl,mkimg)
  10.     String wx,wy,wz,mat="matrix"
  11.     Variable rows=20,cols=20,mktbl=2,mkimg=2
  12.     Prompt wx,"X Wave",popup,WaveList("*",";","")
  13.     Prompt mat,"Output matrix name"
  14.     Prompt wy,"Y Wave",popup,WaveList("*",";","")
  15.     Prompt rows,"number of rows for matrix"
  16.     Prompt wz,"Z Wave",popup,WaveList("*",";","")
  17.     Prompt cols,"number of columns for matrix"
  18.     Prompt mktbl,"Put matrix in new table?",popup,"Yes;No"
  19.     Prompt mkimg,"Display matrix as image?",popup,"Yes;No"
  20.  
  21.     Silent 1;PauseUpdate
  22.     // Make matrix that spans X and Y
  23.     Make/O/N=(rows,cols) $mat
  24.     WaveStats/Q $wx
  25.     SetScale/I x, V_min, V_max, "",$mat
  26.     WaveStats/Q $wy
  27.     SetScale/I y, V_min, V_max, "",$mat
  28.     // Make a temporary contour plot
  29.     // so we can use ContourZ to interpolate from X,Y,Z into MatrixXY
  30.     Display/W=(0,30,200,80)    // teeny window
  31.     DoWindow/C WM_XYZtoMatrix
  32.     AppendXYZContour $wz vs {$wx ,$wy};ModifyContour $wz autoLevels={*,*,0},update=1,labels=0
  33.     ModifyGraph axThick=0,nolabel=2;Textbox/A=LC/F=0 "Computing "+mat;DoUpdate
  34.     $mat= ContourZ("","",0,x,y)
  35.     DoWindow/K WM_XYZtoMatrix
  36.     Preferences 1
  37.     if( mktbl == 1)
  38.         Edit $mat
  39.     endif
  40.     if( mkimg == 1)
  41.         Display;AppendImage $mat
  42.     endif
  43. End
  44.  
  45. // Converts three waves containing X, Y, and Z values into
  46. // a matrix of Z values that spans the given (or auto) X and Y range
  47. Macro XYZtoMatrixRange(wx,mat,wy,rows,wz,cols,xmin,xmax,ymin,ymax)
  48.     String wx,wy,wz,mat="matrix"
  49.     Variable rows=20,cols=20,xmin=NaN,xmax=NaN,ymin=NaN,ymax=NaN
  50.     Prompt wx,"X Wave",popup,WaveList("*",";","")
  51.     Prompt mat,"Output matrix name"
  52.     Prompt wy,"Y Wave",popup,WaveList("*",";","")
  53.     Prompt rows,"number of rows for matrix"
  54.     Prompt wz,"Z Wave",popup,WaveList("*",";","")
  55.     Prompt cols,"number of columns for matrix"
  56.     Prompt xmin,"matrix min X, or NaN for auto min X"
  57.     Prompt xmax,"matrix max X, or NaN for auto max X"
  58.     Prompt ymin,"matrix min Y, or NaN for auto min Y"
  59.     Prompt ymax,"matrix max  Y, or NaN for auto max Y"
  60.  
  61.     Silent 1;PauseUpdate
  62.     // Make matrix that spans X and Y
  63.     Make/O/N=(rows,cols) $mat
  64.     WaveStats/Q $wx
  65.     if(numtype(xmin)==0)
  66.         V_min=xmin
  67.     endif
  68.     if(numtype(xmax)==0)
  69.         V_max=xmax
  70.     endif
  71.     SetScale/I x, V_min, V_max, "",$mat
  72.     WaveStats/Q $wy
  73.     if(numtype(ymin)==0)
  74.         V_min=ymin
  75.     endif
  76.     if(numtype(ymax)==0)
  77.         V_max=ymax
  78.     endif
  79.     SetScale/I y, V_min, V_max, "",$mat
  80.     // Make a temporary contour plot
  81.     // so we can use ContourZ to interpolate from X,Y,Z into MatrixXY
  82.     Display/W=(0,30,200,80)    // teeny window
  83.     DoWindow/C WM_XYZtoMatrix
  84.     AppendXYZContour $wz vs {$wx ,$wy};ModifyContour $wz autoLevels={*,*,0},update=1,labels=0
  85.     ModifyGraph axThick=0,nolabel=2;Textbox/A=LC/F=0 "Computing "+mat;DoUpdate
  86.     $mat= ContourZ("","",0,x,y)
  87.     DoWindow/K WM_XYZtoMatrix
  88. End
  89.